package com.lv.common.dialog

import android.content.Context
import android.widget.TextView
import com.lv.common.R
import com.lv.common.base.BaseDialog
import com.lv.common.dialog.manager.ChainNode
import com.lv.common.dialog.manager.DialogChain
import com.lv.common.imp.OnDialogListener
import com.lv.common.imp.OnDialogSureListener

/**
 * 作者： ygx
 * 创建日期：2023/3/21 4:32 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 * -    _              _           _     _   ____  _             _ _
 * -   / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 * -  / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 * - / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 * -/_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 * <p>
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 * 描述：带取消回调的Dialog
 */
class TipsCancel2Dialog : BaseDialog, ChainNode {
    private var title: String? = null
    private var tv_title: TextView? = null
    private var tv_cancel: TextView? = null
    private var tv_sure: TextView? = null
    private var mChainId: Int = 0

    constructor(mContext: Context?, isCancelable: Boolean, isBackCancelable: Boolean) : super(
        mContext,
        isCancelable,
        isBackCancelable
    ) {
    }

    constructor(
        mContext: Context?,
        title: String?,
        isCancelable: Boolean,
        isBackCancelable: Boolean,
        onDialogListener: OnDialogListener?
    ) : super(mContext, isCancelable, isBackCancelable) {
        this.title = title
        this.onDialogListener = onDialogListener
    }

    constructor(
        mContext: Context?,
        isCancelable: Boolean,
        isBackCancelable: Boolean,
        gravity: Int,
        widthIsMatch: Boolean,
        heightIsMatch: Boolean
    ) : super(mContext, isCancelable, isBackCancelable, gravity, widthIsMatch, heightIsMatch) {
    }

    override fun initView() {
        tv_title = findViewById(R.id.tv_title)
        tv_cancel = findViewById(R.id.tv_cancel)
        tv_sure = findViewById(R.id.tv_sure)
        initEvnet()
    }

    private fun initEvnet() {
        tv_title?.text = title
        tv_sure?.setOnClickListener {
            onDialogListener?.onSureClick("")
            dismiss()
        }
        tv_cancel!!.setOnClickListener {
            onDialogListener?.onCancelClick()
            dismiss()
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.dialog_tips_2
    }

    private var onDialogListener: OnDialogListener? = null

    fun setChainId(chainId: Int) {
        mChainId = chainId
    }

    fun setCancelText(text: String) {
        tv_cancel?.text = text
    }

    fun setConfrimText(text: String) {
        tv_sure?.text = text
    }

    override fun getId(): Int = mChainId

    override fun proceed(chain: DialogChain?) {
        show()
        setOnDismissListener { dialog -> chain?.proceed() }
    }
}